import dao.CroRoleDao;
import entity.CroRole;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * Created by xuweijie on 2017/4/20.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/spring/spring-*.xml" )
public class testinsert {

    @Autowired
    private CroRoleDao croRoleDao;

    @Test
    @Transactional(readOnly = false)
    public void testinsert(){
//        CroRoleDao croRoleDao=new CroRoleDao();
        CroRole croRole=new CroRole();
//        croRole.setId("1234");
        croRole.setRolename("一般管理员");
        croRole.setDescription("拥有一般权限");
        String s = (String) croRoleDao.save(croRole);

        System.out.println(s);

//        System.out.println(cr.getId());
//        System.out.println(cr.getRolename());
//        System.out.println(cr.getDescription());
    }

    @Test
    @Transactional(readOnly = true)
    public void testQuery(){
        CroRole cr = croRoleDao.getById("1");

        System.out.println(cr.getId());
        System.out.println(cr.getRolename());
        System.out.println(cr.getDescription());
    }

    @Test
    @Transactional(readOnly = false, propagation = Propagation.SUPPORTS)
    public void testUpdate(){
        CroRole cr = croRoleDao.getById("2");
        cr.setDescription("hello World");
        try{
            croRoleDao.update(cr);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println(cr.getId());
        System.out.println(cr.getRolename());
        System.out.println(cr.getDescription());
    }

    @Test
    @Transactional
    public void testDelete(){
        croRoleDao.delete("2");
    }
}
